angular.module('flower',['ng','ngRoute','ngAnimate']).config(function($routeProvider){$routeProvider
    .when('/start',{templateUrl:'tpl/start.html',controller:'startCtrl'})
    .when('/main',{templateUrl:'tpl/main.html',controller:'mainCtrl'})
    .when('/detail/:dishID',{templateUrl:"tpl/detail.html", controller:'detailCtrl'})
    .otherwise({redirectTo:'/start'})
})
    .controller('startCtrl',function(){
        $('.start img').hover(function(){
            $(this).attr('src','img/img.jpg');
        }
            ,function(){
                $(this).attr('src','img/img1.jpg');
            });
    })
    .controller('mainCtrl',function($scope,$http){
        $scope.isHasMore =true;
        $http.get('data/dish_getData.php').success(function(data){
                    $scope.dishArr = data;
                    if(data.length<4){
                        $scope.isHasMore = false;
                    };
            });
        //点击加载更多
        $scope.loadMore = function(){
            var count = $scope.dishArr.length;
            $http.get('data/dish_getData.php?start='+count)
                .success(function(data){
                $scope.dishArr = $scope.dishArr.concat(data);
                if(data.length<5){
                    $scope.isHasMore = false;
                };
            });
        };
        //监视搜索文本框的录入：录入的数据有效，进行查询
        $scope.$watch('search_txt',function(){
            //加入严格的正则表达式的校验
            if($scope.search_txt){
                console.log($scope.search_txt);
                $http.get('data/dish_getDataByKW.php?kw='+$scope.search_txt)
                    .success(function (data) {
                        $scope.dishArr = data;
                    });
            }
        });

    })
    .controller('detailCtrl',function($scope,$http,$routeParams){
        //得到main页面传来的参数
        var id = parseInt($routeParams.dishID);
        console.log(id);
        //请求php页面，把id传入，得到返回的结果
        $http.get('data/dish_getDataByProduct.php?did='+id)
            .success(function(data){
                $scope.dish = data[0];
                //console.log(data[0]);
            });
    })
    .controller('indexCtrl',function($scope,$location){
        $scope.jump = function(url){
            $location.path(url);
        }
    })